package com.jinshan.controller;

import com.jinshan.response.RetVal;
import com.jinshan.service.AliyunVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/aliyun/video")
@CrossOrigin
public class AliyunVideoController {
    @Autowired
    private AliyunVideoService videoService;

    @PostMapping("/uploadVideo")
    public RetVal uploadVideoToAliyun(MultipartFile file) throws Exception {
        String videoId = videoService.uploadVideoToAliyun(file);
        return RetVal.success().data("videoId", videoId);
    }

    @DeleteMapping("/{videoId}")
    public RetVal deleteVideoFromAliyun(@PathVariable String videoId) throws Exception{
        videoService.deleteVideoFromAliyun(videoId);
        return RetVal.success();
    }

    @DeleteMapping("/deleteMultipleVideos")
    public RetVal deleteMultipleVideosFromAliyun(@RequestParam List<String> videoIds) throws Exception {
        String strVideoIds = String.join(",", videoIds);
        videoService.deleteVideoFromAliyun(strVideoIds);
        return RetVal.success();
    }
}
